package gui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import mappers.MessageMapper;
import mappers.StudyMapper;
import mappers.TeacherMapper;
import domains.Message;
import domains.Study;
import domains.Teacher;

public class AddStudyGUI {
	private JFrame addStudyFrame;
	private JPanel panel, panel1;
	private JLabel studyLbl, studyLbl2, teacherLbl, semesterLbl;
	private JTextField studyTF, studyTF2, teacherTF;
	private GridLayout layout;
	private JComboBox semester, teacher;
	private JButton addBtn, cancelBtn;
	
	
	public AddStudyGUI(){
		addStudyFrame = new JFrame();
		addStudyFrame.setTitle("Add Study");
		addStudyFrame.setLayout(new BorderLayout());
		addStudyFrame.setSize(400,300);
		
		layout = new GridLayout(0,2,1,0);
		
		panel = new JPanel();
		panel.setLayout(layout);
		layout.setVgap(0);
		
		studyLbl = new JLabel("Study name: ");
		studyTF = new JTextField(15);
		
		studyLbl2 = new JLabel("Classroom: ");
		studyTF2 = new JTextField(15);
			
		//StudentsLbl = new JLabel("Students names:");
		
		teacherLbl = new JLabel("Teachers: ");
		//teacherTF = new JTextField(15);
		
		semesterLbl = new JLabel("Semester: ");
		
		String[] semesterString = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
		semester = new JComboBox(semesterString);
		semester.setSelectedIndex(0);
		//semester.addActionListener(this);
		semester.setBounds(200, 100, 50, 50);
		
		TeacherMapper tMapper = new TeacherMapper();

		DefaultComboBoxModel model = new DefaultComboBoxModel(tMapper.selectTeacherName().toArray());
		teacher = new JComboBox();
		//teacher.setSelectedIndex(0);
		teacher.setModel(model);

		panel.add(studyLbl);
		panel.add(studyTF);
		panel.add(studyLbl2);
		panel.add(studyTF2);
		panel.add(semesterLbl);
		panel.add(semester);
		panel.add(teacherLbl);
		panel.add(teacher);
		
		panel1 = new JPanel(new FlowLayout(FlowLayout.RIGHT));
		addBtn = new JButton("Add");
		addBtn.addActionListener(new ActionListener(){
			public void actionPerfromed(ActionEvent arg0){
				/*Study st = new Study(teacherTF.getText(), studyTF2.getText(), studyTF.getText(), );
				StudyMapper stdMapper = new StudyMapper();
				stdMapper.createStudy(st);	*/
			}

			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				
			}
		});
		cancelBtn = new JButton("Cancel");
		cancelBtn.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				addStudyFrame.setVisible(false);
			}		
		});
		
		panel1.add(addBtn);
		panel1.add(cancelBtn);
			
		addStudyFrame.add(panel, BorderLayout.WEST);
		addStudyFrame.add(panel1, BorderLayout.SOUTH);
		addStudyFrame.pack();
		addStudyFrame.setVisible(true);
		
	}

}
